//
//  YLAmountInvestedViewController.m
//  YLFinanceService
//
//  Created by she1323 on 2017/9/15.
//  Copyright © 2017年 she1323. All rights reserved.
//

#import "YLAmountInvestedViewController.h"
#import "YLMineMoneyViewModel.h"
#import "YLMineMoneyTableViewCell.h"
#import <MJRefresh.h>
@interface YLAmountInvestedViewController ()
@property (nonatomic,strong) YLMineMoneyViewModel *viewModel;

@end

@implementation YLAmountInvestedViewController


- (YLMineMoneyViewModel *)viewModel
{
    if (!_viewModel) {
        _viewModel = [[YLMineMoneyViewModel alloc] init];
    }
    return _viewModel;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"在投金额";
    
    __weak typeof(self) weakSelf = self;
    
    self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        [[weakSelf.viewModel.investmentCommand execute:nil] subscribeNext:^(id  _Nullable x) {
            
            [weakSelf setEmpty];
            
            [weakSelf.tableView reloadData];
            [weakSelf.tableView.mj_header endRefreshing];
            
        }];
    }];
    
    
    [self.tableView.mj_header beginRefreshing];
    
    [self.viewModel.wh_loadDataErrorSubject subscribeNext:^(id  _Nullable x) {
        [weakSelf.tableView.mj_header endRefreshing];
    }];
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    
    return self.viewModel.models.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 52;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 0.0001;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 10;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    YLMineMoneyTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:[YLMineMoneyTableViewCell cellID]];
    cell.model = self.viewModel.models[indexPath.section];
    return cell;
}

- (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView
{
    NSString * text = @"暂无在投金额，赶快去投资吧";
    
    NSDictionary * attributes = @ { NSFontAttributeName:[UIFont boldSystemFontOfSize:14.0f ],
        NSForegroundColorAttributeName:YLLineColor};
    
    return [[ NSAttributedString  alloc ] initWithString:text attributes:attributes];
}


@end
